package cn.ycc1.lianzitu.util;

import java.io.Serializable;

/**
 * @author ycc
 * @date 2025/1/11
 */
public class Result<T> implements Serializable {
    private int code; // 状态码
    private String msg; // 消息描述
    private T data; // 泛型数据

    // 构造函数
    public Result() {}

    public Result(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    // Getter 和 Setter 方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    // 静态方法快速创建响应对象
    public static <T> Result<T> ok(T data) {
        return new Result<>(200, "success", data);
    }

    public static <T> Result<T> ok() {
        return new Result<>(200, "success", null);
    }

    public static <T> Result<T> error(int code, String msg) {
        return new Result<>(code, msg, null);
    }
    public static <T> Result<T> error(String msg) {
        return new Result<>(400, msg, null);
    }

}
